/*
 * Copyright (C) 2012 Johan Boris Iantila jiantila@gmail.com && http://www.facebook.com/johanboris.iantila
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mg.daloji.antandroyd.ui;

import mg.daloji.antandroyd.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ActionBarView extends LinearLayout implements OnClickListener{
	private View 		mConvertView;
	
	private ImageButton 				mButtonSearch;
	private ImageButton 				mButtonComment;
	private ImageButton 				mButtonHome;
	
	private ProgressBar					mProgressBar;
	
	private TextView 					mTitle;
	
	private OnDispatchClickListener 	mListenerClick;
	
	public interface OnDispatchClickListener {
		public void onDispatchClick(int id);
	}
	
	public ActionBarView(Context context, AttributeSet attrs) {
		
		super(context,attrs);
		
		mConvertView 	= LayoutInflater.from(context).inflate(R.layout.action_bar, this);
		
		mButtonSearch	= (ImageButton)mConvertView.findViewById(R.id.ab_search);
		mButtonComment	= (ImageButton)mConvertView.findViewById(R.id.ab_comment);
		mButtonHome		= (ImageButton)mConvertView.findViewById(R.id.ab_home);
		
		mProgressBar    = (ProgressBar)mConvertView.findViewById(R.id.ab_loading);
		
		mTitle  		= (TextView)mConvertView.findViewById(R.id.ab_title);
		
		mButtonHome.setOnClickListener(this);
		mButtonSearch.setOnClickListener(this);
		mButtonComment.setOnClickListener(this);
		mProgressBar.setOnClickListener(this);		
		
	}
	
	public void showButtonSearch()
	{
		mButtonSearch.setVisibility(View.VISIBLE);
	}
	
	public void showButtonComment()
	{
		mButtonComment.setVisibility(View.VISIBLE);
	}
	
	public void setTitle(String _t)
	{
		mTitle.setText(_t);
	}
	
	public void loading()
	{
		mProgressBar.setVisibility(View.VISIBLE);
	}
	
	public void loaded()
	{
		mProgressBar.setVisibility(View.GONE);
	}
	
	public void onClick(View v) {
		mListenerClick.onDispatchClick(v.getId());		
	}
	
	
	public void setOnDispatchClickListener(OnDispatchClickListener v) {
		mListenerClick = v;
	}

}
